package com.seed.fileud;

import com.seed.core.action.Action;
import com.seed.util.ToSeedKit;
import com.seed.fileud.controller.FileudController;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Map;

public class Fileud {
    private static Map<String, Action> actions;

    /**
     * 根据行为名称获取行为
     * @param actionName 行为名称
     * @param method 请求方法
     * @return 行为对象
     */
    public static Action getAction(RequestMethod method, String actionName) {
        if(actions == null) {
            actions = ToSeedKit.toActions(FileudController.class);
        }

        Action action = actions.get(actionName);
        if(action == null || action.getMethods() == null) return null;

        return action.getMethods().contains(method) ? action : null;
    }
}
